<template>
	<div id='system' v-loading="loading">
		<div class="content-top">
			<span class="h1">放款管理</span>
			<!--			<span class="h2">审批查询</span>-->
		</div>
		<div class="top-btn clearfix">
			<div class="left-content">
				<span class="tip">放款管理</span>
				<el-radio-group v-model="rate" @change = "change()">
					<el-radio :label="1">逾期</el-radio>
					<el-radio :label="2">正常</el-radio>
					<el-radio :label="3">已还清</el-radio>
					<el-radio :label="0">全部</el-radio>
				</el-radio-group>
				<el-checkbox v-model="checked" style="margin-left: 10px;" @change="fksj()">放款时间</el-checkbox>
				<el-checkbox v-model="checkes" style="margin-left: 10px;" @change="hksj()">还款时间</el-checkbox>
			</div>
			<div class="right-search1">
				<el-input v-model="input" placeholder="输入关键词…"></el-input>
				<el-button type="primary" @click="look()" style="margin-left: 10px;">查看</el-button>
				<el-button type="primary" @click="execl()">导出excel</el-button>
			</div>
		</div>
		<div style="margin-bottom: 15px;">
			<div style="display: inline-block;" v-show="fk">
				<span>放款时间</span>
				<el-date-picker v-model="fksDate" type="date" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" placeholder="选择日期">
				</el-date-picker><span style="padding: 0 10px;">至</span>
				<el-date-picker v-model="fkeDate" type="date" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" placeholder="选择日期">
				</el-date-picker>
			</div>
			<div style="display: inline-block; margin-left: 10px;" v-show="hk">
				<span>还款时间</span>
				<el-date-picker v-model="hksDate" type="date" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" placeholder="选择日期">
				</el-date-picker><span style="padding: 0 10px;">至</span>
				<el-date-picker v-model="hkeDate" type="date" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" placeholder="选择日期">
				</el-date-picker>
			</div>
		</div>
		<el-table :data="tableData" style="width: 100%">
			<el-table-column label="姓名">
				<template slot-scope="scope">
					<span v-if='scope.row.MemberInfo'>{{ scope.row.MemberInfo.CNName }}</span>
				</template>
			</el-table-column>
			<el-table-column prop="ReceiveMan" label="收款负责人">
			</el-table-column>
			<el-table-column label="手机号">
				<template slot-scope="scope">
					<span v-if='scope.row.MemberInfo'>{{ scope.row.MemberInfo.Tel }}</span>
				</template>
			</el-table-column>
			<!-- <el-table-column label="QQ">
				<template slot-scope="scope">
					<span v-if='scope.row.MemberInfo'>{{ scope.row.MemberInfo.QQ }}</span>
				</template>
			</el-table-column> -->
			<el-table-column label="微信">
				<template slot-scope="scope">
					<span v-if='scope.row.MemberInfo'>{{ scope.row.MemberInfo.WX }}</span>
				</template>
			</el-table-column>
			<el-table-column prop="LoanDate" label="放款日期">
			</el-table-column>
			<el-table-column prop="RefundDate" label="还款日期">
			</el-table-column>
			<el-table-column prop="LMoney" label="放款金额">
			</el-table-column>
			<el-table-column prop="AccountType" label="放款渠道">
			</el-table-column>
			<el-table-column prop="Interest" label="利息">
			</el-table-column>
			<el-table-column prop="AlRefundMoney" label="还款金额">
			</el-table-column>
			<el-table-column prop="OutDays" label="超期天数">
			</el-table-column>
			<el-table-column label="备注">
				<template slot-scope="scope">
					<span class="spanConten" @click="beizhu(scope.row.Memo)">{{ scope.row.Memo }}</span>
				</template>
			</el-table-column>
			<el-table-column label="查看">
				<template slot-scope="scope">
					<router-link v-bind="{to:'/creditInfos/'+(scope.row.MemberID)}"><el-button size="mini">风控报告  </el-button></router-link>
				</template>
			</el-table-column>
			
			<el-table-column label="操作">
				<template slot-scope="scope">
					<el-dropdown trigger="click">
						<span class="el-dropdown-link"><el-button type="primary">操作<i class="el-icon-arrow-down el-icon--right"></i></el-button></span>
						<el-dropdown-menu slot="dropdown" class="div">
							<el-dropdown-item>
								<el-button size="small" type="primary" @click="receiva(scope.row.ID,scope.row.AllotID,scope.row.RefundDate,scope.row.OutDays,scope.row.Interest,scope.row.LMoney,scope.row.AlRefundMoney)">收款</el-button>
							</el-dropdown-item>
							<el-dropdown-item>
								<el-button size="small" type="danger" @click="del(scope.row.ID)">删除</el-button>
							</el-dropdown-item>
						</el-dropdown-menu>
					</el-dropdown>
				</template>
			</el-table-column>
		</el-table>
		<div class="pages">
			<el-pagination small :current-page="index" @current-change="handleCurrentChange" layout="prev, pager, next" :total="total" background prev-text='上一页' next-text='下一页'>
			</el-pagination>
		</div>

		<el-dialog title="放款管理" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
			<el-form ref="form" :model="form" label-width="100px">
				<el-form-item label="应还款日期">
					<el-date-picker v-model="datatimes" disabled type="date" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" placeholder="选择日期">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="实际还款日期">
					<el-date-picker v-model="endtimes" type="date" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" placeholder="选择日期">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="逾期天数">
					<el-input v-model="form.days" disabled></el-input>
				</el-form-item>
				<el-form-item label="未还款金额">
					<el-input v-model="form.moeny" ></el-input>
				</el-form-item>
				<el-form-item label="利息">
					<el-input v-model="form.Interest" ></el-input>
				</el-form-item>
				<el-form-item label="还款金额">
					<el-input v-model="form.moenys"></el-input>
				</el-form-item>
				<el-form-item label="还款渠道">
					<el-select v-model="value" placeholder="请选择">
						<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="用户账号">
					<el-input v-model="form.member"></el-input>
				</el-form-item>
				<el-form-item label="还款账号">
					<el-input v-model="form.refund"></el-input>
				</el-form-item>
				<el-form-item label="备注">
					<el-input v-model="form.Memo"></el-input>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="quxia()">取 消</el-button>
				<el-button type="primary" @click="addrefund()">确 定</el-button>
			</span>
		</el-dialog>
		
		<el-dialog title="备注" :visible.sync="beiz" width="30%" :before-close="handleClose">
			<p>{{conten}}</p>
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" @click="guanb()">关 闭</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	import apis from '../../../api/prouserApi'
	export default {
		name: 'credit',
		data() {
			return {
				hkeDate:"",
				hksDate:"",
				fksDate:"",
				fkeDate:"",
				fk:false,
				hk:false,
				checked: false,
				checkes:false,
				conten:'',
				beiz:false,
				loading:true,
				index: 1,
				total: 1,
				dialogVisible: false,
				rate: 0, //分配
				input: '', //搜索
				tableData: [], //获取放款列表
				options: [{
					value: '支付宝',
					label: '支付宝'
				}, {
					value: '微信',
					label: '微信'
				}, {
					value: '银行卡',
					label: '银行卡'
				}],
				value: '',//渠道
				form: {
					needs: '',
					days:'',//逾期天数
					moeny:'',//未还款金额
					moenys:'',//还款金额
					member:'',//用户账号
					refund:'',//还款账号
					Memo:'',//备注
					Interest:''//利息
				},
				datatime: '', //发布时间
				datatimes:"",//预定还款时间
				endtimes:"",//实际还款时间
				ProviderID: '', //商家id
			}
		},
		created() {
			this.ProviderID = sessionStorage.ProviderID
			this.getloanlist(this.index)
		},
		methods: {
			execl(){
				this.loading = true
				this.$axios.post(apis.getloanlist,{
				  "Status":this.rate,
				  "pagePara": {
				    "Para": this.input,
				    "PageSize": 10,
				    "PageIndex": this.index-1,
				    "OrderbyString": "PName",
				    "ToExcel": true,
				  }
				}).then(res=>{
					if(res.data.isOK){
						if(res.data.data.ExcelResult && res.data.data.ExcelResult.isOK) {
							this.loading = false
							var urls = res.data.data.ExcelResult.data.filePath
							window.location.href = apis.host+'/template/'+urls
						} else{
							this.loading = false
							this.$message.error(res.data.data.ExcelResult.msg);
						}
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				})
			},
			handleEdit(index, row) {
				console.log(index, row);
			},
			handleDelete(index, row) {
				console.log(index, row);
			},
			handleClose() {
				this.hk = false
				this.fk = false
				this.beiz = false
				this.dialogVisible = false
			},
			//分页
			handleCurrentChange(val){
				this.index = val
				this.getloanlist(val) 
			},
			getloanlist(val) {
				this.loading = true
				this.$axios.post(apis.getloanlist,{
				  "Status":this.rate,
				  "pagePara": {
				    "Para": this.input,
				    "PageSize": 10,
				    "PageIndex": val-1,
				    "OrderbyString": "PName",
				    "ToExcel": false,
				  },
				  "isLoanDate":this.checked,
			      "LSDate":this.fksDate,
			      "LEDate":this.fkeDate,
			      "isRefundDate":this.checkes,
			      "RSDate":this.hksDate,
			      "REDate":this.hkeDate,
				}).then(res=>{
					if(res.data.isOK) {
						this.loading = false
						this.tableData = res.data.data.Data
						this.total = res.data.data.Items?res.data.data.Items:1
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				})
			},
			look(){
				this.index = 1
				this.getloanlist(this.index)
			},
			//还款
			receiva(loanID,allotID,data,day,Interest,lmony,almoney){
				this.loanID = loanID
				this.allotID = allotID
				this.datatimes = data
				this.form.days = day
				this.form.Interest = Interest
				this.form.moeny = lmony-almoney//未还金额
				this.form.moenys = ""
				this.form.member=""
				this.form.refund = ""
				this.form.Memo=""
				this.value=""
				this.dialogVisible = true
			},
			quxia(){
				this.dialogVisible = false
			},
			//确定还款
			addrefund(){
				this.loading = true
				this.$axios.post(apis.addrefund,{
				  "LoanID":this.loanID,
				  "AllotID": this.allotID,
				  "RefundDate": this.datatimes,
				  "RealRefundDate": this.endtimes,
				  "OutDays":this.form.days,
				  "UnRefundMoney": this.form.moeny,
				  "RefundMoney": this.form.moenys,
				  "RefundAccountType": this.value,
				  "MemberAccountCode": this.form.member,
				  "RefundAccountCode": this.form.refund,
				  "Interest":this.form.Interest,
				  "Memo":this.form.Memo
				}).then(res=>{
					if(res.data.isOK) {
						this.dialogVisible = false
						this.getloanlist(this.index) 
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				})
			},
			//删除
			del(id){
				this.loading = true
				this.$axios.get(apis.delloan+'/'+id).then(res=>{
					if(res.data.isOK) {
						this.loading = false
						this.getloanlist(this.index)
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				})
			},
			change(){
				this.loading = true
				this.index=1
				this.$axios.post(apis.getloanlist,{
				  "Status":this.rate,
				  "pagePara": {
				    "Para": "",
				    "PageSize": 10,
				    "PageIndex": this.index-1,
				    "OrderbyString": "PName",
				    "ToExcel": false,
				  },
				}).then(res=>{
					if(res.data.isOK) {
						this.loading = false
						this.tableData = res.data.data.Data
						this.total = res.data.data.Items?res.data.data.Items:1
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				})
			},
			beizhu(e){
				this.beiz = true
				this.conten = e
			},
			guanb(){
				this.beiz = false
			},
			fksj(){
				if(this.checked){
					this.fk = true
				}else{
					this.fksDate=""
					this.fkeDate=""
					this.fk = false
				}
			},
			fkqd(){
				this.fk = false
			},
			hksj(){
				if(this.checkes){
					this.hk = true
				}else{
					this.hkeDate=""
					this.hksDate=""
					this.hk = false
				}
			},
			hkqd(){
				this.hk = false
			}
		}
	}
</script>

<style>
</style>